﻿@using Guan.CMS.Web.ViewModels.ProductCategory
@model Guan.CMS.Web.ViewModels.Product.ProductFormModel
@{
    ViewBag.Title = "编辑产品";
}
@section Styles{
    <link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/select2.css")"/>
}
@using (Html.BeginForm("Edit", "Product"))
{
    <div class="section-header">
        <div class="title">
            @if (ViewBag.SectionTitleImage != null)
            {
                <img src="@Url.Content("~/Content/Images/Admin/" + ViewBag.SectionTitleImage)" alt="" />
            }
            @ViewBag.Title
        </div>
        <div class="options">
            <input type="submit" value="保存" class="k-button"/>
            <a href="@Url.Action("List")" class="k-button">返回列表</a>
        </div>
    </div>
    <div class="section-body">
        @(Html.Kendo().TabStrip().Name("ArticleEditTab")
            .Items(tabstrip =>
            {
                tabstrip.Add().Text("产品信息").Selected(true).Content(TabBaseInfo().ToHtmlString());
                tabstrip.Add().Text("搜索引擎优化").Content(TabSeoInfo().ToHtmlString());
                tabstrip.Add().Text("产品图片").Content(TabProPic().ToHtmlString());
            }
            ).Animation(false)
        )
    </div>
}

@helper TabBaseInfo()
{
    @Html.HiddenFor(m => m.Id)
    <table class="main">
        <tr>
            <th>@Html.LabelFor(model => model.Name)</th>
            <td>
                @Html.TextBoxFor(model => model.Name,new{@class="k-textbox",style="width:100%;"})
                @Html.ValidationMessageFor(model => model.Name)
            </td>
        </tr>
        <tr>
            <th>@Html.LabelFor(m => m.CategoryId)</th>
            <td>
                @{
                    var categoryList = ViewBag.CategoryId as IEnumerable<ProductCategoryTree>;
                    <select id="selectCategoryList" name="CategoryId" style="width:300px;">
                        <option value=""></option>
                        @if (categoryList != null)
                        {
                            foreach (var item in categoryList)
                            {
                                <optgroup label="@item.Name">
                                    @foreach (var subitem in item.Children)
                                    {
                                        if (subitem.Id == Model.CategoryId)
                                        {
                                            <option value="@subitem.Id" selected="selected">@subitem.Name</option>
                                        }
                                        else
                                        {
                                            <option value="@subitem.Id">@subitem.Name</option>
                                        }
                                    }
                                </optgroup>
                            }
                        }
                    </select>
                }
            </td>
        </tr>
        <tr>
            <th>@Html.LabelFor(model => model.ShortDescription)</th>
            <td>
                @Html.TextAreaFor(model => model.ShortDescription, new { @class = "k-textbox", style = "width:100%;height:6em;" })
                @Html.ValidationMessageFor(model => model.ShortDescription)
            </td>
        </tr>
        <tr>
            <th>@Html.LabelFor(model => model.FullDescription)</th>
            <td>
                @(Html.Kendo().Editor().Name("FullDescription")
                    .Tools(tools => tools
                        .SubScript()
                        .SuperScript()
                        .ViewHtml()
                    )
                    .HtmlAttributes(new { style = "height:400px;" })
                    .ImageBrowser(imageBrower => imageBrower
                        .Image("~/Uploadfiles/Images/{0}")
                        .Read("Read", "ImageBrowser")
                        .Create("Create", "ImageBrowser")
                        .Destroy("Destroy", "ImageBrowser")
                        .Upload("Upload", "ImageBrowser")
                        .Thumbnail("Thumbnail", "ImageBrowser")))
            </td>
        </tr>
        @*<tr>
            <th>@Html.LabelFor(model => model.IsRecommend)</th>
            <td>
                @Html.EditorFor(model => model.IsRecommend)
                @Html.ValidationMessageFor(model => model.IsRecommend)
            </td>
        </tr>*@
        <tr>
            <th>@Html.LabelFor(model => model.IsPublished)</th>
            <td>
                @Html.EditorFor(model => model.IsPublished)
                @Html.ValidationMessageFor(model => model.IsPublished)
            </td>
        </tr>
        @*<tr>
            <th>@Html.LabelFor(model => model.CreatedTime)</th>
            <td>
                @Html.EditorFor(model => model.CreatedTime)
                @Html.ValidationMessageFor(model => model.CreatedTime)
            </td>
        </tr>
        <tr>
            <th>@Html.LabelFor(model => model.UpdatedTime)</th>
            <td>
                @Html.EditorFor(model => model.UpdatedTime)
                @Html.ValidationMessageFor(model => model.UpdatedTime)
            </td>
        </tr>*@
    </table>
}
@helper TabSeoInfo()
    {
    <table class="main">
        <tr>
            <th>@Html.LabelFor(m => m.MetaKeywords)</th>
            <td>@Html.TextBoxFor(m => m.MetaKeywords, new { @class = "k-textbox", style = "width:100%;" })</td>
        </tr>
        <tr>
            <th>@Html.LabelFor(m => m.MetaDescription)</th>
            <td>@Html.TextAreaFor(m => m.MetaDescription, new { @class = "k-textbox", style = "width:100%;height:4em;" })</td>
        </tr>
        <tr>
            <th>@Html.LabelFor(m => m.MetaTitle)</th>
            <td>@Html.TextBoxFor(m => m.MetaTitle, new { @class = "k-textbox", style = "width:100%;" })</td>
        </tr>
        <tr>
            <th>@Html.LabelFor(m => m.FriendlyName)</th>
            <td>@Html.TextBoxFor(m => m.FriendlyName, new { @class = "k-textbox", style = "width:100%;" })</td>
        </tr>
    </table>
}
@helper TabProPic()
    {
    <table class="main">
        <tr>
            <th>当前图片</th>
            <td>
                @{
                    var imgurl = string.IsNullOrWhiteSpace(Model.ImageUrl) ? "~/Content/Images/nopic.jpg" : Model.ImageUrl;
                }
                <img src="@Url.Content(imgurl)" alt=""/>
            </td>
        </tr>
        <tr>
            <th>上传图片</th>
            <td>
                @(Html.Kendo().Upload()
                      .Name("file")
                      .Async(a => a
                                      .Save("FileSave", "Product", new { id = Model.Id })
                                      .Remove("FileRemove", "Product")
                                      .AutoUpload(true)
                      ).Multiple(false)
                      )
            </td>
        </tr>
    </table>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    <script type="text/javascript" src="@Url.Content("~/Scripts/select2.min.js")"></script>
    <script type="text/javascript">
        $(function () {
            $("#selectCategoryList").select2();
        });
    </script>
}